home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-14 | 1.2 KB | 48 lines | [TEXT/MPS ] |
- /* Ariel Tamches (tamches@cs.wisc.edu): This tests linking in a simple non-DLG scanner */
-
- /* All TokenType's must have some end-of-file token; You must define
- * it with setEofToken() to your end of input token.
- *
- * We assume that #tokdefs is employed for this example; i.e., ANTLR does
- * NOT assign token numbers.
- *
- * ANTLR option -gx must be used to turn off generation of DLG crud (when you
- * want to define your own token stream).
- */
-
- #tokdefs "mytokens.h"
-
- /* user must define ANTLRToken outside of #header */
- <<
- typedef ANTLRCommonToken ANTLRToken; /* use a predefined Token class */
- >>
-
- /* At this point, ANTLRToken and ANTLRTokenStream are defined, user must now
- * derive a class from ANTLRTokenStream (which embodies the user's scanner)
- */
- <<#include "MyLexer.h">>
-
- <<
- main()
- {
- /* create one of my scanners */
- MyLexer scan;
- ANTLRTokenBuffer pipe(&scan);
- /* create a parser of type Expr hooked to my scanner */
- Expr parser(&pipe);
- parser.init();
- parser.setEofToken(Eof);
-
- parser.e(); /* start parsing at rule 'e' of that parser */
- }
- >>
-
- class Expr {
-
- e : IDENTIFIER NUMBER
- <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
- Eof
- ;
-
- }
-